import Vue from "vue";
import VueRouter from "vue-router";
import pcHome from "../views/pcHome.vue";
import games from "../views/games/index.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    meta: {
      title: "Home",
      hasLogin: false,
    },
    component: pcHome,
    children: [
      {
        path: "recharge",
        name: "recharge",
        meta: {
          title: "recharge",
          hasLogin: false,
        },
        component: () => import("../views/account/recharge.vue"),
      },
      {
        path: "payment",
        name: "payment",
        meta: {
          title: "payment",
          hasLogin: false,
        },
        component: () => import("../views/account/payment.vue"),
      },
      {
        path: "withdrawal",
        name: "withdrawal",
        meta: {
          title: "withdrawal",
          hasLogin: false,
        },
        component: () => import("../views/account/withdrawal.vue"),
      },
      {
        path: "message",
        name: "message",
        meta: {
          title: "message",
          hasLogin: false,
        },
        component: () => import("../views/account/message.vue"),
      },
      {
        path: "exchange",
        name: "exchange",
        meta: {
          title: "exchange",
          hasLogin: false,
        },
        component: () => import("../views/account/exchange.vue"),
      },
    ],
  },
  {
    path: "/register",
    name: "register",
    meta: {
      title: "register",
      hasLogin: false,
    },
    component: () => import("../views/pcComponents/register.vue"),
  },
  {
    path: "/games",
    name: "games",
    meta: {
      title: "games",
      hasLogin: false,
    },
    component: games,
    children: [
      {
        path: "fish",
        name: "Fishing",
        meta: {
          title: "fish",
          hasLogin: false,
        },
        component: () => import("@/views/games/components/fish.vue"),
      },
      {
        path: "lottery",
        name: "lottery",
        meta: {
          title: "lottery",
          hasLogin: false,
        },
        component: () => import("@/views/games/components/lottery.vue"),
      },
      {
        path: "electronic",
        name: "electronic",
        meta: {
          title: "electronic",
          hasLogin: false,
        },
        component: () => import("@/views/games/components/electronic.vue"),
      },
      {
        path: "chess",
        name: "Chess",
        meta: {
          title: "chess",
          hasLogin: false,
        },
        component: () => import("@/views/games/components/chess.vue"),
      },
      {
        path: "video",
        name: "video",
        meta: {
          title: "video",
          hasLogin: false,
        },
        component: () => import("@/views/games/components/video.vue"),
      },
      {
        path: "sport",
        name: "Sports",
        meta: {
          title: "sport",
          hasLogin: false,
        },
        component: () => import("@/views/games/components/sport.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// router.beforeResolve((to, from, next) => {
//   document.title = to.meta.title;
//   if (to.meta.hasLogin) {
//     let TOKEN = localStorage.getItem('TOKEN');
//     if (TOKEN) {
//       next()
//     } else {
//        next()
//      router.push('/login')
//     }
//   } else {
//     next()
//   }
// })

export default router;
